//
//  LEExplainContentController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/11.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LEExplainContentController.h"

@interface LEExplainContentController ()

@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation LEExplainContentController

- (void)setupUI
{
    [super setupUI];
    if (self.explainMode == Commit) {
        self.title = @"解释内容";
    }else
    {
        self.title = @"申诉内容";
    }

}
#pragma mark- 网络请求
- (void)requestRefreshData
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.model.geval_id forKey:@"geval_id"];
    [dict setObject:self.textView.text forKey:@"geval_explain"];
    
    [SVProgressHUD showWithStatus:@"正在解释"];
    __weak typeof (self) weakSelf = self;
    [API requestPostAppendKey:ServiceExplainCommitListUrl params:dict success:^(NSDictionary *successCode)
    {
        [SVProgressHUD dismiss];
        LELog(@"%s---%d---%@",__func__,__LINE__,successCode);
        id datas = successCode[@"datas"];
        if ([datas isKindOfClass:[NSDictionary class]])
        {
            NSString *error = datas[@"error"];
            if (error)
            {
                [SVProgressHUD showErrorWithStatus:error];
            }
        }else if ([datas isKindOfClass:[NSString class]])
        {
            [SVProgressHUD showSuccessWithStatus:datas];
            //发送通知解释成功.
            weakSelf.model.geval_explain = weakSelf.textView.text;
            [[NSNotificationCenter defaultCenter] postNotificationName:EXPLAIN_COMMIT_NOTIFICATION object:weakSelf.model];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
       
    } falure:^(NSError *er) {
        LELog(@"%s---%d---%@",__func__,__LINE__,er);
        [SVProgressHUD dismiss];
    }];
}

/**
 去申诉
 */
- (void)requestReply
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.complain_id forKey:@"complain_id"];
    [dict setObject:self.textView.text forKey:@"appeal_message"];
    
    [SVProgressHUD showWithStatus:@"正在申诉"];
    __weak typeof (self) weakSelf = self;
    [API requestPostAppendKey:ServiceReplyUrl params:dict success:^(NSDictionary *successCode)
     {
         [SVProgressHUD dismiss];
         LELog(@"%s---%d---%@",__func__,__LINE__,successCode);
         id datas = successCode[@"datas"];
         if ([datas isKindOfClass:[NSDictionary class]])
         {
             NSString *error = datas[@"error"];
             if (error)
             {
                 [SVProgressHUD showErrorWithStatus:error];
             }
         }else if ([datas isKindOfClass:[NSString class]])
         {
             [SVProgressHUD showSuccessWithStatus:datas];
             //发送通知解释成功.
             [[NSNotificationCenter defaultCenter] postNotificationName:REMARK_NOTIFICATION object:self.textView.text];
             [weakSelf.navigationController popViewControllerAnimated:YES];
         }
         
     } falure:^(NSError *er) {
         LELog(@"%s---%d---%@",__func__,__LINE__,er);
         [SVProgressHUD dismiss];
     }];

}

#pragma mark- 点击事件
- (IBAction)sureClick:(UIButton *)sender
{
    if (self.textView.text.length == 0) {
        [SVProgressHUD showInfoWithStatus:@"请输入解释的内容再提交"];

        return;
    }
    if ([self.textView.text isEqualToString:@"输入解释的内容"]) {
        [SVProgressHUD showInfoWithStatus:@"请输入解释的内容再提交"];
        return;
    }
    if (self.explainMode == Commit) {
        [self requestRefreshData];
    }
    if (self.explainMode == Remark) {
        //去申诉ServiceReplyUrl
        [self requestReply];
    }
}

@end
